package com.eascs.admin.sys.organ;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.eascs.admin.common.controller.BaseMasterViewController;
import com.eascs.admin.sys.organ.form.OrgForm;
import com.eascs.app.dao.PageResult;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;
import com.eascs.workflow.common.entity.sys.ActOrgEntity;
import com.eascs.workflow.common.service.sys.SysOrgService;
import com.eascs.workflow.common.vo.ModelResult;
import com.eascs.workflow.common.vo.OrgUserVO;

/**
 * Created with IntelliJ IDEA.
 * desc:   组织机构controller
 *
 */
@RequestMapping("/organ")
@Controller
public class ActOrganController extends BaseMasterViewController {
	
	@Reference
	private SysOrgService sysOrgService;
	@Value("${web.crm.url}")
	private String crmUrl;
	
	@Override
	public void preHandle() {
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "systemSettings");
	}

    @RequestMapping(value = "/allList", method = RequestMethod.GET)
	public String getOrgAllList(OrgForm orgForm){
    	ViewContext.put(MenuTag.CURRENT_MENU_CODE, "organManage");
    	List<ActOrgEntity> list = sysOrgService.getOrgAllList();
		ViewContext.put("orgList", JSON.toJSONString(list));
		ViewContext.put("crmUrl", crmUrl);
		return "/sys/organInfo";
	}
    
    
    
    @RequestMapping(value = "/getEmployeePageByOrg", method = RequestMethod.GET)
   	public String getEmployeePageByOrg(OrgForm orgForm){
       	if(StringUtils.isNoneBlank(orgForm.getOrgId())){
       		PageResult<OrgUserVO> pageResult = new PageResult<>();
       		ModelResult<PageResult<OrgUserVO>> modelResult =sysOrgService.queryPageActOrgUser(orgForm.getOrgId(), orgForm.getPageSize(), orgForm.getPageIndex());
       		pageResult = modelResult.getModel();
       		ViewContext.put("page", pageResult);
       		String pageUrl="/organ/getEmployeePageByOrg?orgId="+orgForm.getOrgId();
       		ViewContext.put("pageUrl", pageUrl);
       	}
   		return "/sys/orgEmployeePage";
   	}
	
}
